<template>
    <div>
        <ul>
            <li v-for="m in massageList" :key="m.id">
                <!-- <router-link :to="`/home/messages/detail/${m.id}/${m.title}`">{{m.title}}</router-link> -->
                <router-link replace :to="{
                  name:'test',
                    query:{
                        id:m.id,
                        title:m.title
                    }
                }">
                    <!--使用to对象时若使用 pararms 不能用只能用path -->
                    {{m.title}}
                </router-link>
                <button @click="pushshow(m)">push查看</button>
                <button @click=" replaceshow(m)">replace查看</button>
            </li>

        </ul>
        <hr>
        <router-view></router-view>
    </div>

</template>

<script>
    export default {
        name: 'Messages',
        data() {
            return {
                massageList: [
                    { id: '001', title: '消息001' },
                    { id: '002', title: '消息002' },
                    { id: '003', title: '消息003' },
                ]
            }
        },
        methods: {
            pushshow(m) {
                // console.log(this.$router);
                this.$router.push({
                    name: 'test',
                    query: {
                        id: m.id,
                        title: m.title
                    }
                })
            },
            replaceshow(m) {
                this.$router.replace({
                    name: 'test',
                    query: {
                        id: m.id,
                        title: m.title
                    }
                })
            }
        },
        beforeDestroy() {
            console.log("Message组件被销毁了");
        }

    }
</script>
<style>
</style>